/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ConnectionsCommands;

import Gear.Factory;

import java.net.Socket;

/**
 * Implement received command to list available peers.
 *
 * @author Rodrigo Martins Racanicci
 */
public class ConnectionCommandLsPeers implements ConnectionCommand {


    @Override
    public void execute(Socket client, String[] args) {
        synchronized (this) {
            String peers = "";

            Factory.getInstance().getTracker().getPeers();

            for (String p : Factory.getInstance().getTracker().getPeers()) {
                peers = peers.concat(p.concat(" "));
            }

            Factory.getInstance().getTracker().sendCommand(client, peers);
            Factory.getInstance().getTracker().closeClient(client);
        }
    }
}
